package com.lms.classloader;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-05-11 07:26
 * @Description: ${Description}
 */
public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        Class<Demo> demoClass = Demo.class;
        ClassLoader loader = demoClass.getClassLoader();  //获取加载该类的类加载器
        while (loader!=null){
            System.out.println(loader);
            loader = loader.getParent();  //获取类加载器的父类加载器
        }
        System.out.println("-------");
        MyClassLoader myClassLoader = new MyClassLoader();
        Class<?> aClass = myClassLoader.loadClass("com.lms.classloader.Demo");
        loader = aClass.getClassLoader();  //获取加载该类的类加载器
        while (loader!=null){
            System.out.println(loader);
            loader = loader.getParent();  //获取类加载器的父类加载器
        }
    }
}
